<template>
  <div class="tab-bar-item" @click="itemClick">
    <div v-if="!isActive">
      <slot name="item-icon">
      </slot>
    </div>
    <div v-else>
      <slot name="item-icon-active">
      </slot>
    </div>
    <div :style="styleObject">
      <slot name="item-text">
      </slot>
    </div>
  </div>
</template>

<script>
/**
 * this.$route  代表当前活跃组件
 */
export default {
  name: "TabbarItem",
  data(){
    return {
    }
  },
  computed: {
    isActive(){
      return this.$route.path.indexOf(this.path)!=-1
    },
    styleObject(){
      return this.isActive?{color:this.activeColor}:{}
    }
  },
  props:{
    path:{
      type: String
    },
    activeColor: {
      type: String,
      default: 'red'
    }
  },
  methods: {
    itemClick(){
      this.$router.replace(this.path)
    }
  }

}
</script>

<style scoped>
.tab-bar-item{
  flex: 1;
  text-align: center;
  height: 49px;
}
.tab-bar-item img{
  width: 23px;
  height: 23px;
  margin-top: 3px;
  vertical-align: middle;
  margin-bottom: 2px;
}
</style>
